/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.crystalrange.documents.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.documents.dao.DocumentCategoryDao;
import org.crystalrange.documents.model.DocumentCategory;
import org.crystalrange.documents.service.DocumentCategoryService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

/**
 *
 * @author Krzysiek
 */
public class DocumentCategoryServiceImpl implements DocumentCategoryService {

    private DocumentCategoryDao documentCategoryDao;
    private UserService userService;

    public DocumentCategoryDao getDocumentCategoryDao() {
        return documentCategoryDao;
    }

    public void setDocumentCategoryDao(DocumentCategoryDao documentCategoryDao) {
        this.documentCategoryDao = documentCategoryDao;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public DocumentCategory create(String username) {
        User currentUser = this.userService.findByUsername(username);   
        
        DocumentCategory documentCategory = new DocumentCategory();
        documentCategory.setCreatedBy(currentUser);
        documentCategory.setCreatedDate(new Date());
        
        return documentCategory;
    }

    public boolean save(DocumentCategory documentCategory) {
        return this.documentCategoryDao.save(documentCategory);
    }

    public boolean remove(DocumentCategory documentCategory) {
        return this.documentCategoryDao.remove(documentCategory);
    }

    public DocumentCategory find(Long id) {
        return this.documentCategoryDao.find(id);
    }

    public List<DocumentCategory> findAll() {
        return this.documentCategoryDao.findAll();
    }

    public SearchResult<DocumentCategory> searchAndCount(Search search) {
        return this.documentCategoryDao.searchAndCount(search);
    }

    public List<DocumentCategory> search(Search search) {
        return this.documentCategoryDao.search(search);
    }

    public DocumentCategory searchUnique(Search search) {
        return this.documentCategoryDao.searchUnique(search);
    }
    
}
